<?php


namespace app\common\model;

use think\Db;

class Comment{
    public function getPageCommentByNid($nid, $from, $length){
        $sql = "select user.`uid`,user.`username`,`content`,`ctime`,`nid` from comment left join user on user.uid = comment.uid where nid = :nid  order by ctime DESC limit :from, :length";
        return Db::query($sql,['nid'=>$nid,'from'=>$from,'length'=>$length]);
    }

    public function getCommentCountByNid($nid){
        $sql = "select COUNT(*) as totalCount from comment where nid = :nid ";
        return Db::query($sql,['nid'=>$nid]);
    }

    public function add($uid, $content, $nid){
        $sql =  "insert into comment (uid, content, nid) VALUE (:uid, :content, :nid) ";
        return Db::execute($sql, ['uid'=>$uid,'content'=>$content,'nid'=>$nid]);
    }
}